

-----------------Pharmacy-/ReceiptAreaTypeId"=1;------------
with T as(
 select PSH."PharmacySaleHeaderId",PSH."PatientId" 
	from "PharmacySaleHeader" PSH 
) 
update "AppointmentTransaction" P set "PatientId" = T."PatientId" 
from T 
where P."AppointmentId" = T."PharmacySaleHeaderId" and P."ReceiptAreaTypeId"=1;


-----------------patient Registration-/ReceiptAreaTypeId"=3;------------

update "AppointmentTransaction" P set "PatientId" = P."AppointmentId"

where  P."ReceiptAreaTypeId"=3;
-----------------Appointment-/ReceiptAreaTypeId"=4;------------


with T as(
 select A."AppointmentId",A."PatientId" 
	from "Appointment" A
) 
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where  P."ReceiptAreaTypeId"=4 and P."AppointmentId" = T."AppointmentId"

-------------Appointment Cancel-/ReceiptAreaTypeId"=5;------------

with T as(
 select A."AppointmentId",A."PatientId" 
	from "Appointment" A
) 
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where  P."ReceiptAreaTypeId"=5 and P."AppointmentId" = T."AppointmentId"

-----------------Cancelpatient Registration-/ReceiptAreaTypeId"=6;------------

update "AppointmentTransaction" P set "PatientId" = P."AppointmentId"
where  P."ReceiptAreaTypeId"=6;

-----------------PharmacyReturn -/ReceiptAreaTypeId"=7;------------

with T as(
 select PSH."SaleReturnHeaderId",PSH."PatientId" 
	from "SaleReturnHeader" PSH 
) 
update "AppointmentTransaction" P set "PatientId" = T."PatientId" 
from T 
where P."AppointmentId" = T."SaleReturnHeaderId" and P."ReceiptAreaTypeId"=7;

-------------------------labs-/ReceiptAreaTypeId"=8;--------------------------------------













